import os

class iniconfig:
        f=""
        def __init__(self,file):
                self.f=file
                if not os.path.exists(file):
                        a=open(file,"w")
                        a.close()
                        
        def setfile(self,file):
                self.f=file
                if not os.path.exists(file):
                        a=open(file,"w")
                        a.close()           
                        
        def get_item(self,str):
                a=open(self.f,"r")
                b=a.readlines()
                a.close()
                for c in b:
                        if c.startswith("#"):
                                continue
                        if c.startswith(str+"="):
                                return c[len(str)+1:].replace("\n","").replace("\r","")
                return ""
                        
        def set_item(self,name,str):
                a=open(self.f,"r")
                b=a.readlines()
                d=b
                a.close()
                i=-1
                for c in b:
                        i=i+1
                        if c.startswith("#"):
                                continue
                        if c.startswith(name+"="):
                                d[i]=name+"="+str+"\n"
                                a=open(self.f,"w")
                                a.writelines(d)
                                a.close()
                                return
                a=open(self.f,"a")
                a.write(name+"="+str+"\n")
                a.close()                
                
                